package com.woniuxy.joylifeshop.service.serviceImpl;

import com.woniuxy.common.entity.ShopOrderItem;
import com.woniuxy.common.entity.ShopOrderItemExample;
import com.woniuxy.common.mapper.ShopOrderItemMapper;
import com.woniuxy.joylifeshop.exception.OrderManagementException;
import com.woniuxy.joylifeshop.service.OrderManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderManagementServiceImpl implements OrderManagementService {

    @Autowired
    ShopOrderItemMapper shopOrderItemMapper;

    /**
    * @Author SooYoo
    * @Description 多条件查询item
    * @Param 
    * @Return 
    **/
    @Override
    public List<ShopOrderItem> readOrderItemByCondition(ShopOrderItem shopOrderItem) {

        try {
            ShopOrderItemExample shopOrderItemExample = new ShopOrderItemExample();
            ShopOrderItemExample.Criteria criteria = shopOrderItemExample.createCriteria();
            criteria.andMerchantIdEqualTo(shopOrderItem.getMerchantId());
            if (shopOrderItem.getId()!=null && !shopOrderItem.getId().equals("")) {
                criteria.andIdEqualTo(shopOrderItem.getId());
            }
            if (shopOrderItem.getName()!=null && !shopOrderItem.getName().equals("") ) {
                criteria.andNameEqualTo(shopOrderItem.getName());
            }
            if (shopOrderItem.getItemId()!=null&& !shopOrderItem.getItemId().equals("")) {
                criteria.andItemIdEqualTo(shopOrderItem.getItemId());
            }

            List<ShopOrderItem> shopOrderItems = shopOrderItemMapper.selectByExample(shopOrderItemExample);

            return shopOrderItems;
        } catch (Exception e) {
            e.printStackTrace();
            throw new OrderManagementException();
        }
    }
}
